package com.ruoyi.business.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.business.vo.TSureInfoVo;
import com.ruoyi.business.service.ITSureInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 报到信息Controller
 *
 * @author Tellsea
 * @date 2024-02-01
 */
@Api(tags = "报到信息Controller")
@RestController
@RequestMapping("/business/sureInfo")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TSureInfoController extends BaseController {

    private final ITSureInfoService tSureInfoService;

    @ApiOperation("查询报到信息列表")
    @PreAuthorize("@ss.hasPermi('business:sureInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<TSureInfoVo> list(TSureInfoVo entity) {
        return tSureInfoService.queryList(entity);
    }

    @ApiOperation("查询报到信息所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(TSureInfoVo entity) {
        return AjaxResult.success("查询成功", tSureInfoService.queryAll(entity));
    }

    @ApiOperation("导出报到信息列表")
    @PreAuthorize("@ss.hasPermi('business:sureInfo:export')")
    @Log(title = "报到信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSureInfoVo entity) {
        List<TSureInfoVo> list = tSureInfoService.queryAll(entity);
        ExcelUtil<TSureInfoVo> util = new ExcelUtil<>(TSureInfoVo.class);
        util.exportExcel(response, list, "报到信息数据");
    }

    @ApiOperation("获取报到信息详细信息")
    //@PreAuthorize("@ss.hasPermi('business:sureInfo:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", tSureInfoService.queryById(id));
    }

    @ApiOperation("新增报到信息")
    @PreAuthorize("@ss.hasPermi('business:sureInfo:add')")
    @Log(title = "报到信息", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TSureInfoVo entity) {
        return toAjax(tSureInfoService.save(entity));
    }

    @ApiOperation("修改报到信息")
    @PreAuthorize("@ss.hasPermi('business:sureInfo:edit')")
    @Log(title = "报到信息", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody TSureInfoVo entity) {
        return toAjax(tSureInfoService.updateById(entity));
    }

    @ApiOperation("删除报到信息")
    @PreAuthorize("@ss.hasPermi('business:sureInfo:remove')")
    @Log(title = "报到信息", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tSureInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
